﻿using System;

namespace WindowsFormsApplication1
{
    class ReactionTimeFeedback
    {
        int reactionMs = 500;

        int total = 0;

        int repeat;

        double targetAvg;

        double avg;

        public ReactionTimeFeedback(int reactionMs, int repeat, double targetAvg)
        {
            this.reactionMs = reactionMs;
            total = 0;
            this.repeat = repeat;
            this.targetAvg = targetAvg;
            avg = targetAvg;
        }

        public int nextReactionMs(bool correct)
        {
            ++total;
            avg = (correct ? 1 : 0) / 2 + avg / 2;

            if ((total % repeat) == 0)
            {
                reactionMs = (int)(reactionMs * (1 + targetAvg - avg));
            }

            return reactionMs;
        }
    }
}
